package com.jindy.module.oaWorkSummaryApply.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.module.oaDepartApproval.controller.SyOaDepartController;
import com.jindy.module.oaDepartApproval.domain.SyOaDepart;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.module.oaWorkSummaryApply.domain.SyOaWorkSummary;
import com.jindy.module.oaWorkSummaryApply.service.ISyOaWorkSummaryService;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 工作总结Controller
 * 
 * @author jindy
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/module/oaWorkSummaryApply")
public class SyOaWorkSummaryController extends BaseController
{
    private static final Logger LOGGER = LoggerFactory.getLogger(SyOaWorkSummaryController.class);

    @Autowired
    private ISyOaWorkSummaryService syOaWorkSummaryService;

    /**
     * 查询工作总结列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaWorkSummaryApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyOaWorkSummary syOaWorkSummary)
    {
        startPage();
        List<SyOaWorkSummary> list = syOaWorkSummaryService.selectSyOaWorkSummaryList(syOaWorkSummary);
        return getDataTable(list);
    }

    /**
     * 导出工作总结列表
     */
    @PreAuthorize("@ss.hasPermi('module:oaWorkSummaryApply:export')")
    @Log(title = "工作总结", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyOaWorkSummary syOaWorkSummary)
    {
        List<SyOaWorkSummary> list = syOaWorkSummaryService.selectSyOaWorkSummaryList(syOaWorkSummary);
        ExcelUtil<SyOaWorkSummary> util = new ExcelUtil<SyOaWorkSummary>(SyOaWorkSummary.class);
        util.exportExcel(response, list, "工作总结数据");
    }

    /**
     * 获取工作总结详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:oaWorkSummaryApply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syOaWorkSummaryService.selectSyOaWorkSummaryById(id));
    }

    /**
     * 新增工作总结
     */
    @PreAuthorize("@ss.hasPermi('module:oaWorkSummaryApply:add')")
    @Log(title = "工作总结", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyOaWorkSummary syOaWorkSummary)
    {
        return toAjax(syOaWorkSummaryService.insertSyOaWorkSummary(syOaWorkSummary));
    }

    /**
     * 修改工作总结
     */
    @PreAuthorize("@ss.hasPermi('module:oaWorkSummaryApply:edit')")
    @Log(title = "工作总结", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyOaWorkSummary syOaWorkSummary)
    {
        return toAjax(syOaWorkSummaryService.updateSyOaWorkSummary(syOaWorkSummary));
    }

    /**
     * 删除工作总结
     */
    @PreAuthorize("@ss.hasPermi('module:oaWorkSummaryApply:remove')")
    @Log(title = "工作总结", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syOaWorkSummaryService.deleteSyOaWorkSummaryByIds(ids));
    }

    /**
     * 提交申请
     */
    @Log(title = "工作总结", businessType = BusinessType.UPDATE)
    @PostMapping( "/submitApply/{id}")
    @ResponseBody
    public AjaxResult submitApply(@PathVariable Long id) {
        try {
            SyOaWorkSummary syOaWorkSummary = syOaWorkSummaryService.selectSyOaWorkSummaryById(id);
            syOaWorkSummaryService.submitApply(syOaWorkSummary);
        } catch (Exception e) {
            LOGGER.error("工作总结提交申请出错",e);
            return error("工作总结提交申请出错：" + e.getMessage());
        }
        return success();
    }

}
